package com.community.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.community.dao.IBaseDao;
import com.community.entity.Article;
import com.community.entity.Book;
import com.community.service.IBookService;

@Service
public class BookServiceImpl implements IBookService{
	
	@Autowired
	private IBaseDao<Book> bdao;

	@Override
	public List<Book> getBookLimitRand(int limit) {
		// TODO Auto-generated method stub
		
	String sql = "select * from shengya_book ORDER BY RAND() limit "+limit;
		
		List<Object[]> object = bdao.findBySql(sql);
		List<Book> blist = new ArrayList<>();
		Book b ;
		for (Object[] objects : object) {
			b = new Book();
			b.setId(Long.valueOf(objects[0].toString()));
			b.setName(objects[7].toString());
			b.setBookImage(objects[6].toString());
			blist.add(b);
		}
		
		return blist;
	}

}
